package com.hnguigu.health.houduan.lcj.controller_lcj;

import com.google.gson.Gson;
import com.hnguigu.health.houduan.lcj.pojo_lcj.TOrdersetting_lcj;
import com.hnguigu.health.houduan.lcj.service_lcj.TOrderService_lcj;
import com.hnguigu.health.houduan.lcj.service_lcj.TOrdersettingService_lcj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/torset")
public class TOrdersettingController_lcj {
    @Autowired(required = false)
    TOrdersettingService_lcj tosett;

    @Autowired(required = false)
    TOrderService_lcj ts;

    @GetMapping("/getByorderdate")
    @ResponseBody
    public Integer getByorderdate(String orderdate,String orderset,String ii){
        Gson gson = new Gson();
        TOrdersetting_lcj recode = gson.fromJson(orderset, TOrdersetting_lcj.class);
        Integer order = ts.getByOrder(orderdate);
        recode.setReservations(order);
        TOrdersetting_lcj byOrder = tosett.getByOrder(orderdate);
        if(byOrder==null){
            recode.setCreatetime(ii);
            tosett.insertSelective(recode);
            return 1;
        }else{
            recode.setUpdatetime(ii);
            tosett.updateByPrimaryKeySelective(recode);
            return 2;
        }
    }
    @GetMapping("getByorderSett")
    @ResponseBody
    public TOrdersetting_lcj getByorderSett(String orderdate){
        TOrdersetting_lcj byOrder = tosett.getByOrder(orderdate);
        return byOrder;
    }
}
